<?php
class Template {
	var $template_dir;
	var $vars = array();
	

	function Template($root = "") {
		$this->template_dir = $root;
	}

    function assign($name, $value = '') {
		if(is_array($name)) {
			foreach($name as $key=>$val) {
				$this->vars[$key] = $val;
			}
		} else {
		    $this->vars[$name] = is_object($value) && $value instanceof Template ? $value->fetch() : $value;
		}
    }

	function fetch($filename) {
		ob_start();
		extract($this->vars);
		require_once($this->template_dir."/".$filename);
		$content = ob_get_contents();
		ob_end_clean();

		return $content;
	}

	function display() {
		foreach(func_get_args() as $key=>$val) {
			print($this->fetch($val));
		}
	}
}
?>